package appfuse.framework;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import org.apache.log4j.PropertyConfigurator;
import org.apache.log4j.xml.DOMConfigurator;

public class InitServlet extends HttpServlet {
	/**
	 * 
	 */
	private static final long serialVersionUID = -4732275095584204353L;

	public void init() throws ServletException {
		try {
			String log4jfile = getInitParameter("log4j-init-file");
			if (log4jfile == null) {
				System.out.println("没有启用日志系统,如果需要启用日志系统,请正确配置log4j-init-file参数.");
			} else if (log4jfile.endsWith(".properties")) {
				String prefix = getServletContext().getRealPath("/");
				
				String file = getInitParameter("log4j-init-file"); 
				if (file != null) {
					PropertyConfigurator.configure(prefix + file);
					System.out.println("日志系统已启用.");
				}else{
					System.out.println("日志配置文件不存在.");
				}
			} else if (log4jfile.endsWith(".xml")) {
				String prefix = getServletContext().getRealPath("/");
				
				String file = getInitParameter("log4j-init-file"); 
				if (file != null) {
					DOMConfigurator.configure(prefix + file);
					System.out.println("日志系统已启用.");
				}else{
					System.out.println("日志配置文件不存在.");
				}
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

	public void destroy() {
	}
}
